package com.amon.amonplayer.rxjava;

public class ObservableJust<T> extends Observable<T> {
    private final T mValue;

    public ObservableJust(T s) {
        this.mValue = s;
    }

    @Override
    protected void subscribeActual(Observer<T> s) {
        ScalarDisposable<T> sd = new ScalarDisposable<>(s, mValue);
        s.onSubscribe();
        sd.run();
    }

    private static class ScalarDisposable<T> {
        private final Observer<? super T> observer;
        private final T mValue;

        public ScalarDisposable(Observer<? super T> s, T value) {
            this.observer = s;
            this.mValue = value;
        }

        public void run() {
            try {
                observer.onNext(mValue);
                observer.onComplete();
            } catch (Exception e) {
                observer.onError(e);
            }
        }
    }
}
